//
//  HWRechargePackageButton.m
//  嗨文
//
//  Created by 响当当 on 2019/2/14.
//  Copyright © 2019年 dongzheng. All rights reserved.
//

#import "HWRechargePackageButton.h"

@interface HWRechargePackageButton()
@property (nonatomic, strong)UILabel *iconLabel;//角标
@property (nonatomic, strong)UILabel *moneyLabel;//金钱
@property (nonatomic, strong)UILabel *timeLabel;//时间
@end

@implementation HWRechargePackageButton

- (UILabel *)iconLabel
{
    if (!_iconLabel)
    {
        _iconLabel = [HWUtilties creatLabelWithFrame:CGRectMake(95*kUIScaleBasePlus,0,70*kUIScaleBasePlus,16*kUIScaleBasePlus)
                                        textAligment:NSTextAlignmentCenter
                                            textClor:LCHexColor(0xFFFFFF)
                                            textFont:8*kUIScaleBasePlus];
        _iconLabel.backgroundColor = LCHexColor(0xF54337);
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:_iconLabel.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(4, 4)];
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
        maskLayer.frame = _iconLabel.bounds;
        maskLayer.path = maskPath.CGPath;
        _iconLabel.layer.mask  = maskLayer;
    }
    return _iconLabel;
}

- (UILabel *)moneyLabel
{
    if (!_moneyLabel)
    {
        _moneyLabel = [HWUtilties creatLabelWithFrame:CGRectMake(15*kUIScaleBasePlus,22*kUIScaleBasePlus,self.frame.size.width-30*kUIScaleBasePlus,20*kUIScaleBasePlus)
                                         textAligment:NSTextAlignmentLeft
                                             textClor:LCHexColor(0xF54337)
                                             textFont:25*kUIScaleBasePlus];
    }
    return _moneyLabel;
}

- (UILabel *)timeLabel
{
    if (!_timeLabel)
    {
        _timeLabel = [HWUtilties creatLabelWithFrame:CGRectMake(15*kUIScaleBasePlus,CGRectGetMaxY(self.moneyLabel.frame)+10*kUIScaleBasePlus,self.frame.size.width-30*kUIScaleBasePlus,20*kUIScaleBasePlus)
                                         textAligment:NSTextAlignmentLeft
                                             textClor:LCHexColor(0x343434)
                                             textFont:12*kUIScaleBasePlus];
    }
    return _timeLabel;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.layer.masksToBounds = YES;
        self.layer.cornerRadius = 4;
        self.layer.borderColor = LCHexColor(0xF54337).CGColor;
        self.layer.borderWidth = 1;
        
        [self addSubview:self.iconLabel];
        [self addSubview:self.moneyLabel];
        [self addSubview:self.timeLabel];

    }
    return self;
}

- (void)getRechargeDate:(NSDictionary *)dic isChangeCoin:(NSString *)hide
{
    
    NSString *goodsNum = [NSString stringWithFormat:@"%@",dic[@"goodsNum"]];
    NSString *moneyStr = [NSString stringWithFormat:@"%@.00",dic[@"cashAmount"]];
    
    
    if ([hide isEqualToString:@"1"])
    {
        if ([moneyStr isEqualToString:@"10.00"])
        {
            moneyStr = [NSString stringWithFormat:@"%ld.00",moneyStr.integerValue+2];
        }
    }
  
    
    if ([goodsNum isEqualToString:@"1"])
    {
        self.iconLabel.hidden = YES;
    }
    else
    {
        self.iconLabel.hidden = NO;
        self.iconLabel.text = [NSString stringWithFormat:@"每月仅需%.1ld元",([moneyStr integerValue])/3];
    }
    
    self.moneyLabel.attributedText = [moneyStr addAttriButedString:[NSString stringWithFormat:@"¥ %@",moneyStr]
                                                             Color:LCHexColor(0xF54337)
                                                              Font:[UIFont systemFontOfSize:20*kUIScaleBasePlus]
                                                              rang:NSMakeRange(0,1)];
    
    self.timeLabel.text = [NSString stringWithFormat:@"%@个月",goodsNum];
}

- (void)changeColor:(NSInteger)idx
{
    if (idx == 1)
    {
        self.moneyLabel.textColor = LCHexColor(0xF54337);
        self.timeLabel.textColor = LCHexColor(0x343434);
        self.backgroundColor = [UIColor clearColor];
        self.iconLabel.textColor = [UIColor whiteColor];
        self.iconLabel.backgroundColor = LCHexColor(0xF54337);
    }
    else
    {
        self.moneyLabel.textColor = [UIColor whiteColor];
        self.timeLabel.textColor = [UIColor whiteColor];
        self.iconLabel.backgroundColor = [UIColor whiteColor];
        self.iconLabel.textColor = LCHexColor(0xF54337);
        self.backgroundColor = LCHexColor(0xF54337);
    }
}
@end
